package com.zxe.freshserver.mapper;

import com.github.pagehelper.Page;
import com.zxe.commonserver.annotation.AutoFill;
import com.zxe.commonserver.enumeration.OperationType;
import com.zxe.freshserver.pojo.Fresh;
import com.zxe.freshserver.pojo.FreshPageQueryDTO;
import com.zxe.freshserver.pojo.FreshVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;


@Mapper
public interface FreshMapper {
    /**
     * 根据id查询分类是否关联具体生鲜
     * @param categoryId
     * @return
     */
    @Select("select count(category_id) from fresh where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

    /**
     * 插入生鲜数据
     * @param fresh
     */
    @AutoFill(value = OperationType.INSERT)
    void insert(Fresh fresh);

    /**
     * 生鲜分页查询
     * @param freshPageQueryDTO
     * @return
     */
    Page<FreshVO> pageQuery(FreshPageQueryDTO freshPageQueryDTO);

    /**
     * 根据主键查询生鲜
     * @param id
     * @return
     */
    @Select("select * from fresh where id = #{id}")
    Fresh getById(Long id);

    /**
     * 根据主键删除生鲜
     * @param id
     */
    @Delete("delete from fresh where id = #{id}")
    void deleteById(Long id);

    /**
     * 修改生鲜
     * @param fresh
     */
    @AutoFill(value = OperationType.UPDATE)
    void update(Fresh fresh);

    /**
     * 根据分类id查询生鲜
     * @param categoryId
     * @return
     */
    @Select("select * from fresh where category_id = #{categoryId} and status = 1")
    List<FreshVO> findByCategoryId(Long categoryId);
}
